discerne type patterns
Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.
Discerne cases can test nominal type members and bind the narrowed value.
Syntax: मिलाओ <union> { स्थिति <type> स्थिर <name> { ... } }
Category#
control-flow
Related#
Examples#
radix/corpus/discerne/type-patterns.fab (canonical · feature)#
Discerne cases can test nominal type members and bind the narrowed value.
# Type-pattern cases use the same member predicate as `है` and bind the
# narrowed value for the arm body.
class Formal {
var string greeting
}
class Casual {
var string greeting
}
fn classify(Formal ∪ Casual u) → string {
match u {
case Formal const f {
return f.greeting
}
case Casual const c {
return c.greeting
}
}
}
main {
const Formal f ← Formal { greeting = "formal" }
const Casual c ← Casual { greeting = "casual" }
print classify(f)
print classify(c)
}Expected output:
formal
casual